Network Security
Symmetric Cryptography
2.1 Basics of Cryptography
Goals of Cryptography
What Does Secure Communication Mean?
- Confidentiality (Privacy/Secrecy): Only the intended recipient can see the communicated message
- Integrity (Authenticity): The communication is generated by the alleged sender
- Availability: Typically out of scope for cryptography (handled by other security mechanisms)
Symmetric (Private-Key) Cryptography
In symmetric cryptography, Alice and Bob share the same private key for both encryption and decryption.
Key Capabilities
- Confidential Message Transmission:
- One-time Pad
- Stream Ciphers
- Block Ciphers
- Authenticated Message Transmission:
- Message Authentication Codes (MACs)
Historical Context: Substitution Ciphers
General Substitution Cipher
Encryption: Each letter X in plaintext P is replaced with π(X)
Decryption: Each letter Y in ciphertext is replaced with π⁻¹(Y)
Alphabet: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
π = B A D C Z H W Y G O Q X S V T R N M L K J I P F E U
Plaintext: BECAUSE → Ciphertext: AZDBJSZ
Strength and Weakness
- Strength: Key space size is 26! ≈ 4×10²⁶ (difficult exhaustive search)
- Historical Significance: Dominated secret writing throughout the first millennium A.D.
- Critical Weakness: Vulnerable to frequency analysis
- Languages have characteristic letter frequencies
- Substitution ciphers preserve these statistical features
- Attackers can use letter frequency patterns to break the cipher
One-Time Pad
• Plaintext space = Ciphertext space = Key space = {0,1}ⁿ
• Key is chosen uniformly at random
• Key length equals message length
Operation
Decryption: Plaintext = Ciphertext ⊕ Key
Plaintext: 11011011
Key: 01101001
Ciphertext: 10110010 (Plaintext ⊕ Key)
Decryption: 10110010 ⊕ 01101001 = 11011011 ✓
Shannon (Information-Theoretic) Security
Formal Definition: Given any ciphertext, each plaintext of the same length is equally likely
Security Level: Secure even against adversaries with unbounded computational resources
One-Time Pad achieves perfect secrecy!
Critical Requirements for One-Time Pad
- Key must be truly random (not pseudo-random)
- Using text from a book as a key is NOT one-time pad and can be broken
Key Reuse Prohibition:
- Key must NEVER be reused
- Reusing a key creates a “Two-Time Pad” which is completely insecure
- We’ll see attack examples later in wireless communication security
The “Bad News” Theorem
Proof Intuition: To associate each possible plaintext with a ciphertext while maintaining perfect secrecy, we need at least one distinct key per plaintext.
Implication: Perfect secrecy comes at the cost of key management – you need as much secret key material as you have message data.
2.2 Stream Ciphers & Adversarial Models
Stream Ciphers Overview
Use a Pseudo-Random Number Generator (PRNG) to expand a short random seed into a long keystream
PRNG Functionality
(where s << n)
- Input: Short (e.g., 128-bit) truly random seed
- Output: Long string that “looks random”
- Secret Key: The seed itself
- Encryption: Ekey[M] = M ⊕ PRNG(key)
Pseudorandom Generator (PRG) Properties
- Receives a short truly random seed as input
- Stretches it into a long string that is pseudorandom
- Produces output that is computationally indistinguishable from truly random
Key Property: Adversary with bounded computational resources cannot distinguish PRG output from truly random output
Stream Cipher Examples
- Based on: Hash functions, HMAC, block ciphers
- Historical (Broken): RC4-based PRG (widely used, but now broken)
- Modern (Potentially Good): Salsa20, ChaCha20
Properties of Stream Ciphers
Performance
- Typical stream ciphers are very fast
- Efficient for real-time communication
Usage Concerns
- Content Scrambling System (CSS): Uses Linear Feedback Shift Registers incorrectly
- Wired Equivalent Privacy (WEP): Uses RC4 incorrectly
Security Analysis
- Adversary can learn the keystream (PRNG(key))
- Security depends entirely on PRNG unpredictability
- Does NOT have perfect secrecy (computational security only)
Adversarial Models for Ciphers
- The language of the plaintext is known to the adversary
- The nature of the cipher is known to the adversary
Attack Models (Increasing Power)
| Attack Type | Adversary Capabilities | Security Level |
|---|---|---|
| Ciphertext-Only | Knows only ciphertexts | Weakest adversary |
| Known-Plaintext | Knows some plaintext-ciphertext pairs | Moderate adversary |
| Chosen-Plaintext (CPA) | Can choose messages and obtain their ciphertexts | Minimum required security today |
| Chosen-Ciphertext | Can choose ciphertexts and obtain their plaintexts | Strongest adversary |
Chosen-Plaintext Attack (CPA) – Detailed
- Crook #1 changes PIN to a number of his choice (chosen plaintext)
- PIN is encrypted and transmitted: cipher(key, PIN)
- Crook #2 eavesdrops and learns the ciphertext
- Repeat for multiple PIN values to build a database
The CPA Security Game
- Attacker does not know the secret key
- Attacker chooses as many plaintexts as desired and receives corresponding ciphertexts
- When ready, attacker picks two plaintexts M₀ and M₁
- Attacker is even allowed to pick plaintexts for which they previously learned ciphertexts
- Attacker receives either ciphertext of M₀ or ciphertext of M₁
- Attacker wins if they can correctly guess which one
Semantic Security Definition
Given a ciphertext (and length) of some unknown message, adversary cannot learn any additional information about the message that can be feasibly extracted
Formal Game: If adversary chooses two messages M₀ and M₁, and is given EK[Mb] where b is randomly chosen from {0,1}, the adversary has little advantage in guessing b
Important Security Result
This is why encryption needs randomness (e.g., random IVs in block cipher modes)
Real Weaknesses of Stream Ciphers
1. Key Stream Reuse
- If the same stream is ever used twice, the cipher becomes easy to break
- “Two-Time Pad” is completely insecure
- Reason: C₁ ⊕ C₂ = (M₁ ⊕ K) ⊕ (M₂ ⊕ K) = M₁ ⊕ M₂ (key cancels out!)
2. Malleability
- Stream ciphers are highly malleable
- Easy to modify ciphertext so plaintext changes predictably
- Example: Flipping bit i in ciphertext flips bit i in plaintext
- Which security property is violated? Integrity!
Computational vs. Perfect Secrecy
| Aspect | Perfect Secrecy | Computational Security |
|---|---|---|
| Security Against | Unbounded adversary | Polynomially-bounded adversary |
| Can Be Broken By | Cannot be broken | Brute force (trying all keys) |
| Key Length | ≥ message length | Fixed (e.g., 128, 256 bits) |
| Examples | One-Time Pad | Stream ciphers, block ciphers |
| Practical? | Difficult (key distribution) | Yes (foundation of modern crypto) |
Proving Computational Security
- Assume that certain problems are hard (require significant computational resources)
- Show that breaking security implies solving the hard problem
- Therefore, if the problem is hard, the scheme is secure
Computational security is the foundation of modern cryptography!
2.3 Block Ciphers
Why Block Ciphers?
- Stream Ciphers: Use different keys in different locations
- Block Ciphers: Make the unit of transformation larger – encrypt block by block rather than letter by letter
Data Encryption Standard (DES)
Historical Background
- Designed by IBM with modifications proposed by the National Security Agency (NSA)
- US national standard from 1977 to 2001
- Was the de facto standard for symmetric encryption
DES Specifications
- Block size: 64 bits
- Key size: 56 bits
- Rounds: 16
- Design focus: Hardware implementations
DES Security Status
- Vulnerable to brute-force attacks (56-bit key is too small)
- Vulnerable to differential cryptanalysis
- Vulnerable to linear cryptanalysis
Advanced Encryption Standard (AES)
Development Process
- In 1997, NIST called for algorithms to replace DES
- Requirements: Unclassified, publicly disclosed, available royalty-free worldwide
- Goal: Replace DES for government and private-sector encryption
- October 2, 2000: Rijndael selected as AES (by Joan Daemen and Vincent Rijmen)
AES Requirements
- Symmetric key cryptography as a block cipher
- Minimum block size: 128 bits
- Key sizes: 128, 192, and 256 bits
AES Features
| Feature | Specification |
|---|---|
| Design Goal | Efficient in both hardware and software across various platforms |
| Block Size | 128 bits (fixed) |
| Key Sizes | 128, 192, or 256 bits (variable) |
| Rounds | 10 (128-bit key) 12 (192-bit key) 14 (256-bit key) |
| Security Status | No known practical weaknesses |
Encryption Modes
A block cipher encrypts only one block. We need methods to:
- Extend encryption to arbitrarily long messages
- Ensure that if the block cipher is secure, the encryption is secure
- Provide semantic security (ciphertext indistinguishability)
Electronic Code Book (ECB) Mode
Operation
- Message is broken into independent blocks
- Each block is encrypted individually with the same key
Properties
- Deterministic: Same plaintext block → same ciphertext block
- Pattern Preservation: Reveals data patterns when blocks repeat
- No Integrity: Blocks can be mixed, matched, or reordered
- Same Key Usage: Same message encrypted the same way every time
Breaking Semantic Security with ECB
- Adversary requests encryption of M₀
- Adversary requests encryption of M₁
- In challenge phase, receives either E(M₀) or E(M₁)
- Adversary compares with previous encryptions to determine which message
- Attack succeeds because ECB is deterministic!
Cipher Block Chaining (CBC) Mode
Operation – Encryption
C₀ = IV
Cᵢ = Ekey(Pᵢ ⊕ Cᵢ₋₁) for i = 1, 2, …, n
Operation – Decryption
Properties
- Randomized Encryption: Same plaintext → different ciphertext (due to random IV)
- Dependency: Each ciphertext block depends on all preceding plaintext blocks
- Semantic Security: Can be proven secure assuming block cipher is a PRP and random IVs are used
- Choose random IV for each encryption
- Protect integrity of IV (should be included in authentication)
- Still does not guarantee integrity by itself
CBC Security Example: Diebold Voting Machines
DesCBCEncrypt((des_c_block*)tmp, (des_c_block*)record.m_Data,
totalSize, DESKEY, NULL, DES_ENCRYPT)
The NULL parameter means no IV was used!
This completely breaks CBC security (reduces to ECB mode).
Counter (CTR) Mode
Operation
- Start with a random counter value
- yᵢ = Ekey[counter + i]
- Cᵢ = Pᵢ ⊕ yᵢ (encryption)
- Pᵢ = Cᵢ ⊕ yᵢ (decryption)
Shared between sender and receiver: Counter (does not need to be secret) and secret key
Performance Measures
| Property | CTR Mode | CBC Mode |
|---|---|---|
| Encryption Parallelizable | ✓ Yes | ✗ No |
| Decryption Parallelizable | ✓ Yes | ✓ Yes |
| Random Read Access | ✓ Yes | ✗ No |
Comparison: ECB vs CBC
When encrypting an image:
- AES in ECB mode: Similar plaintext blocks produce similar ciphertext blocks – the outline of the image remains visible!
- AES in CBC mode: Output looks completely random – no discernible patterns
Lesson: ECB mode preserves patterns in data, making it unsuitable for most applications
Importance of Randomness
- 2012: Flaw found in online encryption systems due to poor random number generation
- Study: “Four of every 1,000 public keys provide no security” due to insufficient randomness
Takeaway: Cryptographic security critically depends on high-quality randomness
2.4 Hash Functions
Motivation: Data Integrity and Source Authentication
- Encryption does NOT protect data from modification by another party
- Need a way to ensure data arrives in its original form
- Need to verify data is coming from an authenticated source
Cryptographic Hash Functions
Definition and Properties
- Input: Bit strings of any length
- Output: n-bit string (fixed length)
- Output Names: Fingerprint, message digest, hash
- Nature: Lossy compression (many-to-one function)
Key Property
Collisions must exist (pigeonhole principle), but finding them should be computationally infeasible
Randomness Property
- H(x) should look “random”
- Every bit should be (almost) equally likely to be 0 or 1
- Changing one bit of input should change approximately half the output bits
Requirements for Cryptographic Hash Functions
1. Preimage Resistant (One-way)
Given y ∈ Y, it is computationally infeasible to find a value x ∈ X such that h(x) = y
2. Second Preimage Resistant (Weak Collision Resistant)
Given x ∈ X, it is computationally infeasible to find a value x’ ∈ X such that x’ ≠ x and h(x’) = h(x)
3. Collision Resistant (Strong Collision Resistant)
It is computationally infeasible to find two distinct values x, x’ ∈ X such that h(x) = h(x’)
Birthday Attack
It is possible to find a collision of a hash function in 2n/2 operations, where 2n is the classical preimage resistance security
- In a classroom of 30 students
- Probability that at least one student shares YOUR birthday: ~7.9%
- Probability that ANY two students share A birthday: ~70%!
Implication for Hash Functions:
A hash function with n-bit output needs n ≥ 256 to provide 128-bit collision resistance
Applications of Hash Functions
Application 1: Password Hashing
- Instead of storing user passwords, store hash(password)
- When user enters password, compute its hash and compare
- System does not store actual passwords!
- Assumes adversary cannot go from hash to password (one-wayness)
Why Hashing is Better Than Encryption for Passwords
- No decryption key to protect
- Even if hash database is stolen, passwords remain protected (if strong)
- One-way nature prevents reconstruction
Solution: Use salt
Store: {salt, Hash(salt, password)}
Salt prevents precomputed rainbow table attacks and ensures same passwords have different hashes
Application 2: Software Integrity
- Manufacturer sends file to users
- Manufacturer publishes hash in trusted medium (e.g., New York Times)
- User downloads file and computes hash
- User compares computed hash with published hash
- If they match, file is authentic
Goal: Integrity, not secrecy
Property Needed: Given goodFile and hash(goodFile), very hard to find badFile such that hash(goodFile) = hash(badFile)
Which Hash Property is Needed?
| Application | Property Needed | Reasoning |
|---|---|---|
| Password Storage | One-wayness | Hard to recover password from hash. But passwords are guessable, so use salt! |
| Software Integrity | Full collision resistance | Software images are not random. Vulnerable to chosen-prefix collision attacks |
Attacker can choose two arbitrarily different documents, then append different calculated values such that the whole documents have equal hash values
Given two different prefixes p₁, p₂, the attack finds two appendages m₁ and m₂ such that:
hash(p₁ || m₁) = hash(p₂ || m₂)
Well-Known Hash Functions
| Hash Function | Output Size | Status |
|---|---|---|
| MD5 | 128 bits | ❌ BROKEN – collision resistance completely broken |
| SHA-1 | 160 bits | ⚠️ VULNERABLE – collision found in 2017, one-wayness still holds |
| SHA-2 Family | 224, 256, 384, 512 bits | ✓ SECURE – currently recommended |
| SHA-3 (Keccak) | Variable | ✓ SECURE – selected by NIST competition |
SHA-3 Selection Process
- NIST organized a competition for new standard hash algorithms
- Selected: Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters, and Gilles Van Assche
Limitation of Using Hash for Authentication
- Anyone can compute the hash of a message (hash function is public)
- Adversary could replace both message and hash
- Authentic channel not always possible
Solution Preview: Use a key to compute the hash → Message Authentication Code (MAC)
2.5 MAC and Authenticated Encryption
Message Authentication Code (MAC)
- Computation: MAC = CK(M)
- Shared Secret: The sender and receiver share key K
- Transmission: Sender sends (M, CK(M))
- Verification: Receiver receives (X, Y) and verifies that CK(X) = Y
Security Property
Provides: Both integrity and authentication – only someone who knows the key can compute correct MAC for a given message
MAC Operation Illustrated
- Alice: Has message and shared key K₁, K₂
- Alice computes: MAC = HMAC(K₂, message)
- Alice sends: (message, MAC)
- Adversary: Can observe but cannot forge valid MAC without key
- Bob receives: (message, MAC)
- Bob computes: HMAC(K₂, message) using his copy of K₂
- Bob verifies: Computed MAC = Received MAC?
- If match: Message is authentic and unmodified
HMAC (Hash-based MAC)
Design and Properties
- Invented by Bellare, Canetti, and Krawczyk (1996)
- Used in SSL/TLS, mandatory for IPsec
Why HMAC Over Encryption?
- Hashing is faster than encryption
- Library code for hash functions widely available
- Can easily replace one hash function with another
- Historically, there were US export restrictions on encryption
Security Status
Combining Encryption and Authentication
Three Approaches
| Approach | Operation | Used In | Security |
|---|---|---|---|
| Authenticate-then-Encrypt (AtE) | a = MAC(x) C = E(x, a) Send: C |
SSL/TLS | ⚠️ Not always secure |
| Encrypt-then-Authenticate (EtA) | C = E(x) a = MAC(C) Send: (C, a) |
IPsec | ✓ Secure |
| Encrypt-and-Authenticate (E&A) | C = E(x) a = MAC(x) Send: (C, a) |
SSH | ❌ Not secure |
Why Encryption Alone is Insufficient
Defense: Authenticate ciphertext, and only decrypt after verifying ciphertext has not changed
Encrypt-then-Authenticate (EtA) is Secure
- C = E(x), a = MAC(C), transmit (C, a)
- Receiver first verifies MAC before any decryption
- No information leakage through decryption failures
- MAC computed on ciphertext provides strong binding
Why AtE and E&A Are Insecure
Authenticate-then-Encrypt (AtE) Vulnerability
- a = MAC(x), C = E(x, a), transmit C
- First step is decryption – its success or failure may leak information
- Reason: MAC is verified only AFTER decryption
- Famous Attack: Decryption oracle attacks on TLS/SSL
Encrypt-and-Authenticate (E&A) Vulnerability
- C = E(x), a = MAC(x), transmit (C, a)
- MAC has no guarantee for confidentiality
- MAC is deterministic: messages are equal ⇒ their MACs are equal
- Result: Breaks chosen-plaintext security
Detailed E&A Attack Scenario
- Alice encrypts msg: Encrypt(K₁, msg)
- Alice computes MAC: MAC = HMAC(K₂, msg)
- Alice sends: (encrypt(msg), MAC(msg))
- Later, Alice sends another message msg2
- Adversary observes: If MAC(msg) = MAC(msg2), then msg = msg2!
- Result: Adversary can tell if messages are the same
Why this breaks security:
- MAC is deterministic: equal messages → equal MACs
- This violates ciphertext indistinguishability
- Breaks chosen-plaintext security
Solutions and Best Practices
Alternative (Also Secure): MAC, then Encrypt
Important Details:
- Do not forget to include IV in MAC computation
- Use separate keys for encryption and MAC (K₁ ≠ K₂)
- If encryption is malleable, attacks are possible even with MAC
Principles of Cryptographic Design
Core Principles
Assume restrictions on adversary’s computational capabilities, NOT on adversary’s strategy!
2. Kerckhoff’s Principle
Keys can be secret, design is public
3. Sufficient Key Length Principle
Number of possible keys should be large enough to make attacks infeasible using best adversary resources expected during sensitivity period of data
4. Limited Key Usage Principle
Refresh keys, use master key-session key combinations
5. Modular Design
Design and analyze simple functions, use them to construct stronger functions in modular ways
6. Well-Defined, Conservative Assumptions
Use well-defined, conservative assumptions and security models
Summary: Key Takeaways
- Cryptography Goals: Confidentiality and Integrity/Authentication
- Perfect Secrecy: One-Time Pad achieves it but impractical (key length = message length)
- Stream Ciphers: Fast but vulnerable to key reuse and malleability
- Block Ciphers: AES is current standard; mode of operation matters (CBC > ECB)
- Hash Functions: Provide integrity; need collision resistance for security
- MACs: Provide authentication and integrity; HMAC is standard
- Authenticated Encryption: Encrypt-then-MAC is the secure approach
- Security Models: Design for chosen-plaintext security minimum